package org.zoomdev.zoom.dao.adapters;

import org.zoomdev.zoom.aop.Setter;
import org.zoomdev.zoom.dao.SqlConfig;

import java.sql.ResultSet;
import java.sql.SQLException;

public class GenerateKeyAdapter {

    private String[] generateKeys;

    private Setter[] setters;

    private ResultSetAdapter[] resultSetAdapters;

    public void setResultSetAdapters(ResultSetAdapter[] resultSetAdapters) {
        this.resultSetAdapters = resultSetAdapters;
    }


    public void setSetters(Setter[] setters) {
        this.setters = setters;
    }

    public String[] getGenerateKeys() {
        return generateKeys;
    }

    public void setGenerateKeys(String[] generateKeys) {
        this.generateKeys = generateKeys;
    }

    public void handle(SqlConfig config, Object data, ResultSet rs) throws SQLException {
        for (int i = 0, c = setters.length; i < c; ++i) {
            setters[i].set(data, resultSetAdapters[i].getObject(rs, i + 1));
        }

    }
}
